#include<iostream>
#include<string>
using namespace std;
class Solution {
public:
    bool backspaceCompare(string s, string t) {
        string sret;
        string tret;
        for (auto e : s)
        {
            if (e == '#')
            {
                if (sret.size())sret.pop_back();
            }
            else  sret.push_back(e);

        }
        for (auto e : t)
        {
            if (e == '#')
            {
                if (tret.size())tret.pop_back();
            }
            else tret.push_back(e);
        }

        if (sret == tret)return true;
        return false;

    }
};